home *** CD-ROM | disk | FTP | other *** search
/ SIGGRAPH 2002 Course Notes / SIGGRAPH 2002 - Course Notes - Disc 1.iso / pc / notes / 16 / supplemental-material / Pharr / matteFalloff.sl next >
Encoding:
Text File  |  2002-04-05  |  847 b   |  33 lines

  1. /*
  2.  * matteFalloff.sl
  3.  *
  4.  * Like the matte shader, but with an additional falloff control that
  5.  * controls the size of the falloff region; values between 0 and .5 
  6.  * make the falloff be over a smaller range, while values between .5
  7.  * and 1 make the falloff be over a larger range.
  8.  *
  9.  * Matt Pharr <mmp@exluna.com>
  10.  */
  11.  
  12. float bias(varying float value, b) {
  13.     float ret = 0;
  14.     if (b > 0) ret = pow(value, log(b) / log(0.5));
  15.     return ret;
  16. }
  17.  
  18. float gain(float value, g) {
  19.     return .5 * ((value < .5) ? bias(2*value, 1-g) :
  20.                                 (2 - bias(2-2*value, 1-g)));
  21. }
  22.  
  23. surface matteFalloff(float Ka = 1, Kd = 1, falloff = 0.5) {
  24.     normal Nf = normalize(faceforward(N, I));
  25.     illuminance(P, Nf, PI/2) {
  26.     Ci += Kd * Cl * gain(Nf . normalize(L),
  27.         clamp(falloff, 0, 1));
  28.     }
  29.     Ci += Ka * ambient();
  30.     Ci *= Cs;
  31. }
  32.  
  33.